using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint;

namespace TST.SharePointObjects.SecurityBluePrint.Pages
{
    public class CreateSecurityBluePrint : LayoutsPageBase
    {
        protected Button buttonCreateBluePrint;
        protected Button buttonCancel;
        protected Label labelCurrentSite;
        protected Label labelUrl;
        protected TextBox editLibrarySiteUrl;
        protected TextBox editEndPoints;

        protected override void OnLoad(EventArgs e)
        {
            buttonCreateBluePrint.Click += new EventHandler(buttonCreateBluePrint_Click);
            buttonCancel.Click += new EventHandler(buttonCancel_Click);
            labelCurrentSite.Text = SPContext.Current.Web.Title;
            labelUrl.Text = SPContext.Current.Web.Url;
            base.OnLoad(e);
        }

        void buttonCancel_Click(object sender, EventArgs e)
        {
            SPUtility.Redirect(SPContext.Current.Web.ServerRelativeUrl, SPRedirectFlags.UseSource, System.Web.HttpContext.Current);
        }

        void buttonCreateBluePrint_Click(object sender, EventArgs e)
        {
            SecurityBluePrint bluePrint = new SecurityBluePrint(editLibrarySiteUrl.Text);
            bluePrint.EndPoints = editEndPoints.Text.Replace("\r\n", ";");
            string redirect = bluePrint.Run(SPContext.Current.Web);
            SPUtility.Redirect(redirect, SPRedirectFlags.UseSource, System.Web.HttpContext.Current);
        }
    }
}
